<template>
  <div id="app">
    <h2>测试题</h2>
    <subject
      v-for="(res, index) in arr"
      :key="index"
      :index="index"
      @res="resFn"
    ></subject>
    <div>
      <flag
        v-for="(result, ind) in arr"
        :key="ind"
        :result="result"
        :ind="ind"
      ></flag>
    </div>
  </div>
</template>

<script>
import Subject from "./components/Subject";
import Flag from "./components/Flag";
export default {
  data() {
    return {
      arr: ["未完成", "未完成", "未完成", "未完成", "未完成"], //保存的是题目做的结果 : 值有3种情况 "未完成" ,"正确","错误"
    };
  },
  components: {
    Subject,
    Flag,
  },
  methods: {
    resFn(resStr, index) {
      //传出来的结果字符串:正确,错误
      this.$set(this.arr, index, resStr); //把结果更新到arr数组里的第几个元素,把里面的值替换掉
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>